//
//  MoreTestView.m
//  Trading365
//
//  Created by Jason on 12-5-16.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MoreTestView.h"
#import "ASIHTTPRequest.h"
#import "FileUploader.h"
#import "XmlRpc.h"

@implementation MoreTestView
@synthesize showTxt;
@synthesize web;
@synthesize imgView;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        countChild = 0;  
        countMain  = 0;  
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
//    NSString *documentsDirectory = [paths objectAtIndex:0];
//    NSString *path = [documentsDirectory stringByAppendingPathComponent:docName];
    
//    NSString *path=@"https://localhost:8443/maoyi365/wall8.jpg";
//    NSURL *url = [NSURL URLWithString:path];
//    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
//    self.web.scalesPageToFit = YES;
//    [self.web loadRequest:request];

//    NSString*filePath = [[NSBundle mainBundle] pathForResource:@"238" ofType:@"html"];
//    NSString*file = [[NSString alloc] initWithContentsOfFile:filePath];
    
//    NSString *htmlStr=@"<html><head>  <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>  <meta http-equiv='Content-Style-Type' content='text/css'>  <title>Maoyi365</title> </head><body><a href='https://localhost:8443/maoyi365/' ><img src='https://localhost:8443/maoyi365/wall8.jpg' /></a></body></html>";
//    NSURL *url=[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
//    NSLog(@"url=%@",url);
//    [self.web loadHTMLString:htmlStr baseURL:url];

    ///////////////////
/*    
    NSString *stringURL = @"https://172.16.15.143:8443/maoyi365/displayCloudImage.svt?file_id=B83619B01FEF9DD69CBDB2A35B2E0A98"; 
    NSURL *url   =   [NSURL URLWithString:stringURL]; 
    ASIHTTPRequest *request = [[[ASIHTTPRequest  alloc] initWithURL:url] autorelease]; 
    [request setValidatesSecureCertificate:NO];
    request.shouldAttemptPersistentConnection   = NO;
    [request startSynchronous]; 
    NSError *error = [request error]; 
    if(!error){ 
//        [web setOpaque:NO];
//        [web setBackgroundColor:[UIColor clearColor]];
        NSString *HTMLData = @"<html><body>sjdksjdkjsdk<img src=\"https://172.16.15.143:8443/maoyi365/displayCloudImage.svt?file_id=B83619B01FEF9DD69CBDB2A35B2E0A98\" alt=\"picture\" width=\"306\"/></body></html>";
        NSLog(@"HTMLData=%@",HTMLData);
        [web loadHTMLString:HTMLData baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
        NSString *html=[request responseString];
        NSLog(@"html=%@",html);
        
//        NSURL *url=[NSURL URLWithString:@"https://172.16.15.143:8443/maoyi365"];
//        [web loadHTMLString:HTMLData baseURL:url];
    } 
*/
    
}

- (void)viewDidUnload
{
    [self setWeb:nil];
    [self setImgView:nil];
    [self setShowTxt:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [web release];
    [imgView release];
    [showTxt release];
    [super dealloc];
}

- (void)uploadedImage:(NSString*)URL sender:(FileUploader*)sender
{
    NSLog(@"url:%@",URL);
    if (URL != nil) {
        NSLog(@"it is upload suc");
    }
    //[self._uActivityIndicator stopAnimating];
}

- (IBAction)OnSavePic:(id)sender {
    

    /////////////
    //    self.imgView.image=
    //保存上传
//    FileUploader* imup = [[FileUploader alloc] init];
//    [imup uploadPic:self.imgView.image delegate:self businessType:@"PERSIONAL_PIC" 
//         businessID:@"12345678" fileID:@"111111111"
//           fileName:@"aaa" memberID:@"0002"];
//    [imup release];
    

    dispatch_async(dispatch_get_global_queue(0, 0), ^{  
        //加入耗时操作  
        XmlRpc *xmlrpc = [[XmlRpc alloc] init];
        NSMutableDictionary *userinfo_tmp=nil ;  
        userinfo_tmp = [xmlrpc Member_Login:@"060001" PassWord:@"123456" Origin:@""];
        NSLog(@"count1=%d",countChild);
        countChild++;
        
        dispatch_async(dispatch_get_main_queue(), ^{  
            //更新UI操作  
            UITextView* textview;
            textview.text = @"hell";
            self.showTxt.text=[NSString stringWithFormat:@"%@",userinfo_tmp];
            NSLog(@"count2=%d",countMain);
             countMain++;
        });  
       
        
    });  
    
}
@end
